//
//  **** COMPLETE ****
//
//  Sensors.c
//  ECGVer2
//
//  Created by FRANCIS PAPINEAU on 12-01-01.
//  Copyright 2012 carleton university. All rights reserved.
//  
//  Using the following protocol defined by Francis Papineau in conjunction with Thai Nguyen:
//      -> "!Lig:00.00Tem:00.00ECG:00.00POT:00.00BAT:00.00IRL:00.00LOW:00.00RES:00.00ArT:00.00ErB:00.00ECP00.00\n"
//      The system then reads values to send via the Serial port defined.
//

/*________________________________________________________________________________*/


void sendSensorValues(){
    
    if(SensorsOK){   
        // The header for the receiving end of the Serial Network
        Serial.print("!");
        
        // The Light value
        Serial.print("Lig:");
        tempLight = analogRead(Light);
        Serial.print(tempLight);
        
        // The tympanic temperature
        Serial.print("Tem:");
        temp = getTermocoupleValue();
        Serial.print(temp);
        
        // The ECG Voltage Level
        Serial.print("ECG:");
        tempECG = analogRead(ECG);
        Serial.print(tempECG);
        
        // The SPO2 Base Measurement using Red Light (approx. 620nm)
        // The measurment is done between a flikr of the LED
        Serial.print("POT:");
        
        // LED ON
        digitalWrite(RedLED, HIGH);
        tempRed = pulseIn(PulseOx, HIGH);
        Serial.print(tempRed);
        
        // LED OFF
        digitalWrite(RedLED, LOW);
        
        // The Battery Voltage Level
        Serial.print("BAT:");
        tempBat = analogRead(Battery);
        Serial.print(tempBat);
        
        // The SPO2 Measurment using IR Light (approx. 960nm)
        // The measurment is done between a flikr of the LED
        Serial.print("IRL:");
        
        // LED ON
        digitalWrite(IrLED, HIGH);
        tempIr = pulseIn(PulseOx, HIGH);
        Serial.print(tempIr);
        
        // LED OFF
        digitalWrite(IrLED, LOW);
        
        // The SPO2 Measurement using Ambient Light
        // -> this is used in a proprietary algorithm to cancel
        // the effect of ambient light in the SPO2 measurement
        Serial.print("LOW:");
        tempError = pulseIn(PulseOx, HIGH);
        Serial.print(tempError);
        
        // The Respiration sensor measurments
        Serial.print("RES:");
        tempRESP = analogRead(Resp);
        Serial.print(tempRESP);
        
        // The Ambient Temperature Reading
        Serial.print("ArT:");
        AmbientTemp = getThermistorValue(analogRead(AmbTemp));
        Serial.print(AmbientTemp);
        
        // The ECG Batt Reading
        Serial.print("ErB:");
        tempECGBat = analogRead(ECGBatt);
        Serial.print(tempECGBat);
        
        // The ECG pulse
        Serial.print("ECP:");
        if(digitalRead(ECGPulse) == HIGH){
            pulse = 1;
        }else{
            pulse = 0;
        }
        ECGPulseTemp = pulseIn(ECGPulse, HIGH);
        Serial.print(ECGPulseTemp);
        
        // The Checksum Character.
        Serial.print("\n");
    }
}

/*________________________________________________________________________________*/
/*________________________________________________________________________________*/
/*________________________________________________________________________________*/

